- Notifications
You must be signed in to change notification settings - Fork 31
/
Copy path206. Reverse Linked List.c
51 lines (39 loc) · 996 Bytes
/
206. Reverse Linked List.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
206. Reverse Linked List
Reverse a singly linked list.
click to show more hints.
Hint:
A linked list can be reversed either iteratively or recursively. Could you implement both?
*/
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
structListNode*reverseList(structListNode*head) {
structListNode*a, *b, *c;
a=NULL;
b=head;
while (b) {
c=b->next;
b->next=a;
a=b;
b=c;
}
returna;
}
/*
Difficulty:Easy
Total Accepted:245.8K
Total Submissions:541.6K
Companies Uber Facebook Twitter Zenefits Amazon Microsoft Snapchat Apple Yahoo Bloomberg Yelp Adobe
Related Topics Linked List
Similar Questions
Reverse Linked List II
Binary Tree Upside Down
Palindrome Linked List
*/